package com.senven.settled.controller;

import com.senven.common.entity.Settledlibrary;
import com.senven.common.vo.CommonResult;
import com.senven.settled.config.OssUtil;
import com.senven.settled.service.ISettledlibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wt
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/settled/settledlibrary")
public class SettledlibraryController {

    @Autowired
    private ISettledlibraryService settledlibraryService;

    //手机端---添加商家入驻的申请信息
    @PostMapping("/insertSettledFindAll")
    public CommonResult insertSettled(@RequestBody Settledlibrary settledlibrary){
        System.out.println(settledlibrary);
        CommonResult result = settledlibraryService.insertSettled(settledlibrary);
        return result;
    }


    //后台----查询所有
    @PostMapping("/findAllSettled")
    public CommonResult findAllSettled(Integer currentPage, Integer pageSize, @RequestBody Map map){
        CommonResult result = settledlibraryService.findAllSettled(currentPage,pageSize,map);
        return result;
    }
    //后台----查询所有状态为未审核的
    @PostMapping("/findAllSettle")
    public CommonResult findAllSettle(Integer currentPage, Integer pageSize){
        CommonResult result = settledlibraryService.findAllSettle(currentPage,pageSize);
        return result;
    }

    //后台----存储商家申请入驻的url地址
    @PostMapping("/upload03")
    public CommonResult upload03(MultipartFile file){
        System.out.println(file);
        try {
            System.out.println("-===============");
            String updd = OssUtil.updd(file);
            return new CommonResult(2000,"上传成功",updd);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new CommonResult(5000,"上传失败",null);
    }
    //商家入驻审核通过，存储商家信息user，给商家角色role，改变审核状态settled
    @PostMapping("/insertUserByRoleBySettled")
    public CommonResult insertUserByRoleBySettled(@RequestBody Settledlibrary settledlibrary){
        System.out.println(settledlibrary);
        CommonResult result = settledlibraryService.insertUserByRoleBySettled(settledlibrary);
        return result;
    }

    //商家入驻审核驳回 --修改setteld表审核状态、添加审核时间--给用户发送失败短信
    @PostMapping("/updateSettledState")
    public CommonResult updateSettledState(@RequestBody Settledlibrary settledlibrary){
        System.out.println(settledlibrary);
        CommonResult result = settledlibraryService.updateSettledState(settledlibrary);
        return result;
    }
}
